package cn.ubeta.b2c.api;

import cn.ubeta.b2c.EmbeddedData;
import cn.ubeta.b2c.bean.PriceInfo;
import cn.ubeta.b2c.bean.ProductInfo;
import cn.ubeta.b2c.bean.StockInfo;
import cn.ubeta.b2c.utils.NetworkCallback;
import cn.ubeta.b2c.utils.NetworkHelper;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.http.GET;
import retrofit2.http.Query;

/**
 * Created by denny on 16/9/5.
 */

public class ApiProduct extends ApiBase<ApiProduct.IProductBiz> {

    @Override
    public String getBasePath() {
            return "gw";
            }

    public static String PATH = new ApiUser().getBasePath();

    /**
     * 用户接口
     */
    interface IProductBiz  {
        @GET("getAreaPrice.do")
        Call<PriceInfo> getPrice(@Query("skuids") String skuids);

        @GET("getAreaStockState.do")
        Call<StockInfo> getStock(@Query("skuids") String skuids);
    }

    /**
     * 获取主页商品列表
     * @param catgId
     * @param cb
     */
    public static void getHomeProductList(int catgId, NetworkCallback cb) {
        List<ProductInfo> test = ProductInfo.getTestData(catgId);
        if (test != null) {
            cb.onResponse(test);
        } else {
            String url = String.format("/list?catgId=%d", catgId);
            NetworkHelper.call(PATH + url, cb);
        }
    }

    /**
     * 获取商品列表价格
     */
    public static void getProductPrice(int brandId, Callback cb) {
        String skuIds = EmbeddedData.getSkuIdsByBrand(brandId);
        new ApiProduct().create().getPrice(skuIds).enqueue(cb);
    }

    /**
     * 获取商品库存信息
     */
    public static void getProductStock(long skuId, Callback cb) {
        new ApiProduct().create().getStock(String.valueOf(skuId) + ",1").enqueue(cb);
    }
}
